import React from "react";
import { shallowEqual } from "react-redux";
import { useAppDispatch, useAppSelector } from "../redux/hook";
import { changeName, backName, addAge } from "../redux/otherSlice";

export const CPage = () => {
  console.log("C渲染了");

  const { name, age } = useAppSelector((state: any) => ({ ...state.other }), shallowEqual);
  const dispatch = useAppDispatch();
  return (
    <div>
      <h1>我是Cpage</h1>
      <h2>我是name:{name}</h2>
      <button
        onClick={() => {
          dispatch(changeName());
        }}
      >
        改变
      </button>
      <button
        onClick={() => {
          dispatch(backName());
        }}
      >
        还原
      </button>
      <h1>我是张三的age:{age}</h1>
      <button
        onClick={() => {
          dispatch(addAge(5));
        }}
      >
        age加五
      </button>
    </div>
  );
};
